#include <bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> m;
signed main() {
  int tc;
  cin >> tc;
  while (tc--) {
    m.clear();
    int n;
    cin >> n;
    int mx = 0, idx = 0;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      m[x]++;
      if (m[x] > mx) {
        idx = x, mx = m[x];
      }
    }
    if (mx == n) {
      cout << 0 << endl;
    } else {
      int ans = 0;
      n -= mx;
      ans++;
      while (true) {
        if (n > mx) {
          ans += mx;
          n -= mx;
          ans++;
          mx *= 2;
        } else {
          ans += n;
          break;
        }
      }
      cout << ans << endl;
    }
  }
}
